package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "前端套餐相关接口")
@RequestMapping("/user/setmeal")
public class SetMealController {

    @Autowired
    private SetMealService setMealService;

    /**
     * 根据分类ID获取套餐信息
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类ID获取套餐")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> list(Long categoryId){
        log.info("当前的分类ID是：{}", categoryId);
        List<Setmeal> setmealList = setMealService.selectSetMealByCateGoryId(categoryId);
        return Result.success(setmealList);
    }

    /**
     * 通过套餐ID获取菜品
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    @ApiOperation("通过套餐ID获取菜品")
    public Result<List<DishItemVO>> selectDishBySetMealId(@PathVariable Long id){
        log.info("当前的套餐ID是：{}",id);
        List<DishItemVO> dishItemVOList = setMealService.selectSetMealByIdGetDishInfo(id);
        return Result.success(dishItemVOList);
    }

}
